		<!-- start content -->
		<div id="content">
			<div class="post">
				<h1 class="title"><?php echo $ts; ?></h1><br /><!--print movie title-->
				<div class="entry">
				
<?php
session_cache_limiter('private, must-revalidate');
session_start();
include 'std_dbs.php';

//text is in search and submitted
$searchstr = strtoupper(addslashes($ts));
$title = addslashes($ts);
$searchquery = "SELECT * FROM Movies WHERE upper(MovTitle) = '".$searchstr."' AND PendStatus = 0";
$searchresults = oci_parse($connect, $searchquery);
oci_execute($searchresults);

//print picture and information
$row = oci_fetch_array($searchresults, OCI_ASSOC);
if (!isset($row['IMGCOVER']))//change default on insertion to this if nothing is entered
	$row['IMGCOVER'] = 'default.jpg';
print "<img src=content/covers/".$row['IMGCOVER']." alt=".$row['MOVTITLE']." /><br />";//image
$my = $row['MOVYEAR'];
print "Release Year: $my";
//if (!isset($row['MOVYEAR']))
//	print "ALLOW REGISTERED USER TO INPUT HERE";
print "<br />";
print "Summary: ".$row['MOVDESC'];
//if (!isset($row['MOVDESC']))
//	print "ALLOW REGISTERED USER TO INPUT HERE";
print "<br />";
print "Budget: ".$row['MOVBUDGET'];
//if (!isset($row['MOVBUDGET']))
//	print "ALLOW REGISTERED USER TO INPUT HERE";
print "<br />";
print "Runtime: ".$row['MOVRUNTIME'];
//if (!isset($row['MOVRUNTIME']))
//	print "ALLOW REGISTERED USER TO INPUT HERE";
print "<br />";

//SHOW TRAILER $row['TRAILER']
//do query to print name of SUBMITTERID


//SUGGESTION
//maybe to a query on usercontent to calculate the average rating
$movid = $row['MOVID'];
 
$searchquery = "SELECT RATING FROM USERCONTENT WHERE MOVID = '".$movid."' AND CONTENTTYPE= '2'";
$searchresults = oci_parse($connect, $searchquery);
oci_execute($searchresults);

$total = 0;
$divisor = 0;

//print picture and information
while($row = oci_fetch_array($searchresults, OCI_ASSOC))
{
	if($row['RATING'] != 0 && $row['RATING'] != '')
	{
		$total = $total + $row['RATING'];
		$divisor++;
	}
}

if($divisor != 0)
{
	$aveRating = $total / $divisor;
	$aveRating = round($aveRating, 2);
}
else
	$aveRating = "Not yet rated!<br />";

echo "Average Rating: $aveRating";

//IMPORTANT, when inserting a movie

//check if favorite and have make favorite button
if (isset($_SESSION['userid'])) {//logged in user
	$userId = $_SESSION['userid'];
	//if favorite show that it is(make able to remove it), else print button to add it
	
	//$query = "SELECT * FROM UserContent......";
	//$searchresults = oci_parse($connect, $query);
	//oci_execute($searchresults);
	
	//print "<form action='myfavorites.php' method='POST'>
			//<input typ";
}




//Free result set
oci_free_statement($stid);


if(isset($_SESSION['user'])) {
//I suggest using 1-10stars instead of half stars, do not use text box smh
//by all means, go ahead....been kinda busy with everything else :)
echo "				<form name='addReview' method='post' action='reviews.php'>
                        	<input type='hidden' name='title' value='".$title."'/>
							Rating: 
							<select name='rating'><option value='1'>1</option><option value='2'>2</option>
							<option value='3'>3</option><option value='4'>4</option><option value='5'>5</option></select><br />
							Review:<br />
							<textarea name='comment' cols=40 rows=6>Enter your review here.</textarea><br />
							<input type='submit' value='Add Review' name='submit'>
							<input type='submit' value='Add to Favorites' name='submitToFav' />
						</form>";
}
else
	echo "<br />You must sign in to post a review!";
echo "<hr> <h2> Reviews </h2>";

$query = "SELECT USERID, MOVID, CONTENTID, CONTENTTYPE, CREATEDATE, RATING, TEXT FROM USERCONTENT WHERE MOVID = $movid AND CONTENTTYPE = 2 ORDER BY CREATEDATE DESC";
$stid = oci_parse($connect, $query);
if($stid == false)
  {
    $e = oci_error($connect);
    echo "ERROR: error parsing query to get movie reviews <br />";
    echo "MSG: ".$e['message']."<br />";
    exit;
  }

$r = oci_execute($stid);

if($r == false)
  {
    $e = oci_error($stid);
    echo "ERROR: error executing query to get movie reviews <br />";
    echo "MSG: ".$e['message']."<br />";
    exit;
  }

echo "<table width='90%'>";
echo "<tr>";
echo "<th>Date</th>";
echo "<th>Username</th>";
echo "<th>Rating</th>";
echo "<th>Comment</th>";
echo "</tr>";
while(($row = oci_fetch_array($stid, OCI_ASSOC)))
  {
        // get the submitter's username from the submitterid
    $subQuery = "SELECT USERNAME FROM USERS WHERE USERID = ".$row['USERID'];
    $subStid = oci_parse($connect, $subQuery);
    if($subQuery == false)
      {
	$submitter = "PARSE ERROR";
      }
    $ret = oci_execute($subStid);
    if($ret == false)
      {
	$submitter = "EXEC ERROR";
      }

    $subRow = oci_fetch_array($subStid);
    $submitter = $subRow['USERNAME'];

    echo "<tr>";
    echo "<td>".$row["CREATEDATE"]."</td>";
    echo "<td>".$submitter."</td>";
    echo "<td>".$row["RATING"]."</td>";
    echo "<td>".$row["TEXT"]."</td>";
    echo "</tr>";
  }
echo "</table>";

//Close database connection
oci_close($connect);
?>

				</div>
			</div>
		</div>
		<!-- end content -->







